package com.flag.liutao.modules.role.controller;


import com.flag.liutao.common.domain.ResponseResult;
import com.flag.liutao.modules.role.param.UserRoleParam;
import com.flag.liutao.modules.role.param.UserRoleQueryParam;
import com.flag.liutao.modules.role.service.IUserRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author godM
 * @since 2022-12-02
 */
@RestController
@RequestMapping("/admin/userRole")
@Api(tags = "任职管理")
@RequiredArgsConstructor
public class UserRoleController {

    private final IUserRoleService userRoleService;

    @GetMapping("page")
    @ApiOperation(value="分页查询任职信息",notes = "授权管理:分页查询任职信息")
    @PreAuthorize("hasAuthority('sys_power:user_role_R')")
    public ResponseResult<Map<String,Object>> getUserRolePage(UserRoleQueryParam param){
        Map<String,Object> map = userRoleService.getUserRolePage(param);
        return ResponseResult.ok(map);
    }

    @PostMapping("add")
    @ApiModelProperty(value = "添加任职信息",notes = "任职管理：添加任职信息")
    @PreAuthorize("hasAuthority('sys_menu:user_role_C')")
    public ResponseResult<String> addUserRole(@Validated  @RequestBody UserRoleParam param ){
        userRoleService.addUserRole(param);
        return ResponseResult.ok("授权成功");
    }


    @PostMapping("edit")
    @ApiModelProperty(value = "修改任职信息",notes = "授权管理：修改任职信息")
    @PreAuthorize("hasAuthority('sys_menu:user_role_U')")
    public ResponseResult<Boolean> editUserRole(@Validated  @RequestBody UserRoleParam param ){
        userRoleService.editUserRole(param);
        return ResponseResult.ok();
    }


    @PostMapping("del")
    @ApiModelProperty(value = "删除任职信息",notes = "授权管理：删除任职信息")
    @PreAuthorize("hasAuthority('sys_menu:user_role_U')")
    public ResponseResult<Boolean> delUserRole(@Validated  @RequestBody UserRoleParam param ){
        userRoleService.delUserRole(param);
        return ResponseResult.ok();
    }

}
